

package com.kimo.shop.user.admin.controller;

import com.kimo.shop.user.comment.model.UserLevelLog;
import com.kimo.shop.user.comment.service.UserLevelLogService;
import com.kimo.shop.common.annotation.SysLog;

import javax.validation.Valid;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import com.kimo.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;


/**
 *
 *
 * @author kimo-taozhouchuan
 * @date 2020-02-26 16:03:14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/user/userLevelLog" )
public class UserLevelLogController {

    private final UserLevelLogService userLevelLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param userLevelLog
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<UserLevelLog>> getUserLevelLogPage(PageParam<UserLevelLog> page, UserLevelLog userLevelLog) {
        return ResponseEntity.ok(userLevelLogService.getPage(page,userLevelLog));
    }


    /**
     * 通过id查询
     * @param levelLogId id
     * @return 单个数据
     */
    @GetMapping("/info/{levelLogId}" )
    public ResponseEntity<UserLevelLog> getById(@PathVariable("levelLogId") Long levelLogId) {
        return ResponseEntity.ok(userLevelLogService.getById(levelLogId));
    }

    /**
     * 新增
     * @param userLevelLog
     * @return 是否新增成功
     */
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelLog:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid UserLevelLog userLevelLog) {
        return ResponseEntity.ok(userLevelLogService.save(userLevelLog));
    }

    /**
     * 修改
     * @param userLevelLog
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('user:userLevelLog:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserLevelLog userLevelLog) {
        userLevelLog.setState(1);
        return ResponseEntity.ok(userLevelLogService.updateById(userLevelLog));
    }

    /**
     * 通过id删除
     * @param levelLogId id
     * @return 是否删除成功
     */
    @SysLog("删除" )
    @DeleteMapping("/{levelLogId}" )
    @PreAuthorize("@pms.hasPermission('user:userLevelLog:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long levelLogId) {
        return ResponseEntity.ok(userLevelLogService.removeById(levelLogId));
    }

}
